﻿using BookStore.Application.User.Dto;
using BookStore.Domain.UserInfo;
using BookStore.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace BookStore.Application.User
{
    public class UserAppService : ApplicationService, IUserAppService
    {
        //private readonly BookStoreDbContext _bookStoreDbContext;
        private readonly IRepository<Users> _userRepository;

        public UserAppService(
            //BookStoreDbContext bookStoreDbContext,
            IRepository<Users> userRepository
            )
        {
            //_bookStoreDbContext = bookStoreDbContext;
            _userRepository = userRepository;
        }

        public async Task<UserDto> GetAsync(string userNo, string password)
        {
            //return await _bookStoreDbContext.Users.FirstOrDefaultAsync(u => u.UserNo == userNo && u.Password == password);
            var user = await _userRepository.GetAsync(u => u.UserNo == userNo && u.Password == password);
            var dto = ObjectMapper.Map<Users, UserDto>(user);
            return dto;
        }

        public async Task<UserDto> GetAsync(string userNo)
        {
            var user = await _userRepository.GetAsync(u => u.UserNo == userNo);
            var dto = ObjectMapper.Map<Users, UserDto>(user);
            return dto;
        }
    }
}
